package com.dudu.log.ticketLog.service.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import net.sf.json.JSONObject;

import com.dudu.enumeration.AbilityTypeEnum;
import com.dudu.log.ticketLog.dao.TicketDao;
import com.dudu.log.ticketLog.service.ITicketService;

import core.CoreDao;
import core.CoreDaoInvoke;

public class TicketServiceImpl implements ITicketService {

    private CoreDao coreDao = CoreDaoInvoke.getInstance();
    private TicketDao ticketDao = new TicketDao();

    /**
     * 查询条数（分页用）
     * 
     * @param paramSql
     * @return
     */
    public Integer getTotalAcount(String paramSql) {
	return ticketDao.getTotalAcount(coreDao, paramSql);
    }

    /**
     * 查询数据（分页）
     * 
     * @param paramSql
     * @param pageSql
     * @return
     */
    public List<JSONObject> queryAll(String paramSql, String pageSql) {
	List<JSONObject> list = ticketDao.queryAll(coreDao, paramSql, pageSql);
	if (null == list) {
	    return list;
	}
	for (JSONObject object : list) {
	    String ability_type = object.optString("ability_type");
	    AbilityTypeEnum ab = AbilityTypeEnum.getAbilityTypeEnum(ability_type);
	    String ability_typevalue = "";
	    if (ab != null) {
		ability_typevalue = ab.getValue();
	    }
	    if (StringUtils.isBlank(ability_typevalue)) {
		object.put("ability_type", ability_type);
	    } else {
		object.put("ability_type", ability_typevalue);
	    }
	}
	return list;
    }

}
